package com.avcdata.aoscustommade.model;

import android.content.Context;

import com.avcdata.aoscustommade.bean.TopBrandAndSelfBrandBean;
import com.avcdata.aoscustommade.main.BaseCallBack;
import com.avcdata.aoscustommade.utils.AvcConstants;
import com.avcdata.aoscustommade.utils.http.AvcHttpUtils;
import com.avcdata.aoscustommade.utils.http.AvcJsonHttpResponseHandler;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by zyh on 17/6/8.
 */

public class CitySelectaActivityModel {
    private final Context mContext;

    public CitySelectaActivityModel(Context context) {
        this.mContext = context;
    }

    /**
     * 获取城市品牌排行
     *
     * @param category
     * @param brand
     * @param topBrandCount
     * @param lastWeek
     * @param lastWeekCount
     * @param bigRegion
     * @param officeName
     * @param cityName
     * @param baseCallBack
     */
    public void loadCityBrandList(String category, String brand, int topBrandCount, String lastWeek, int lastWeekCount, String bigRegion, String officeName, String cityName, final BaseCallBack baseCallBack) {


        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("category", category);
            jsonObject.put("brand", brand);
            jsonObject.put("topBrandCount", topBrandCount);
            jsonObject.put("lastWeek", lastWeek);
            jsonObject.put("lastWeekCount", lastWeekCount);
            jsonObject.put("bigRegion", bigRegion);
            jsonObject.put("officeName", officeName);
            jsonObject.put("cityName", cityName);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        AvcHttpUtils.post(AvcConstants.URLHeaderCitys + "topBrandAndSelfBrand", jsonObject, true, new AvcJsonHttpResponseHandler(mContext, TopBrandAndSelfBrandBean.class) {

            @Override
            public void onSuccess(Object object) {
                super.onSuccess(object);
                TopBrandAndSelfBrandBean bean = (TopBrandAndSelfBrandBean) object;
                baseCallBack.onSuccess(bean);
            }

            @Override
            public void onFailure() {
                super.onFailure();
                baseCallBack.onFailure();
            }

            @Override
            public void onFailure(Throwable throwable) {
                super.onFailure(throwable);
                baseCallBack.onFailure(throwable);
            }


        });
    }

    /**
     * 城市行业销售额同环比
     *
     * @param topBrandCount
     * @param lastWeek
     * @param lastWeekCount
     * @param brand
     * @param bigRegion
     * @param officeName
     * @param cityName
     * @param baseCallBack
     */
    public void loadCityIndustrySales(int topBrandCount, String lastWeek, int lastWeekCount, String brand, String bigRegion, String officeName, String cityName, final BaseCallBack baseCallBack) {
        JSONObject jsonObject = new JSONObject();
        try {
            JSONArray array = new JSONArray();
            array.put("热水器");
            array.put("燃气热水器");
            array.put("电储水热水器");
            array.put("净化器");
            array.put("净水器");
            jsonObject.put("categories", array);
            jsonObject.put("topBrandCount", topBrandCount);
            jsonObject.put("lastWeek", lastWeek);
            jsonObject.put("lastWeekCount", lastWeekCount);
            jsonObject.put("brand", brand);
            jsonObject.put("bigRegion", bigRegion);
            jsonObject.put("officeName", officeName);
            jsonObject.put("cityName", cityName);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        AvcHttpUtils.post(AvcConstants.URLHeaderCitys + "brandAmountRatio", jsonObject, true, new AvcJsonHttpResponseHandler(mContext) {

            @Override
            public void onSuccess(JSONObject jsonObject) {
                super.onSuccess(jsonObject);
                baseCallBack.onSuccess(jsonObject);
            }

            @Override
            public void onFailure() {
                super.onFailure();
                baseCallBack.onFailure();
            }

            @Override
            public void onFailure(Throwable throwable) {
                super.onFailure(throwable);
                baseCallBack.onFailure(throwable);
            }
        });

    }

    /**
     * 城市趋势图
     *
     * @param category
     * @param brand
     * @param topBrandCound
     * @param lastWeek
     * @param lastWeekCount
     * @param bigRegion
     * @param officeName
     * @param cityName
     * @param baseCallBack
     */
    public void loadCityTrend(String category, String brand, int topBrandCound, String lastWeek, int lastWeekCount, String bigRegion, String officeName, String cityName, final BaseCallBack baseCallBack) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("category", category);
            jsonObject.put("brand", brand);
            jsonObject.put("topBrandCount", topBrandCound);
            jsonObject.put("lastWeek", lastWeek);
            jsonObject.put("lastWeekCount", lastWeekCount);
            jsonObject.put("bigRegion", bigRegion);
            jsonObject.put("officeName", officeName);
            jsonObject.put("cityName", cityName);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        AvcHttpUtils.post(AvcConstants.URLHeaderCitys + "trend", jsonObject, true, new AvcJsonHttpResponseHandler(mContext) {

            @Override
            public void onSuccess(JSONObject jsonObject) {
                super.onSuccess(jsonObject);
                baseCallBack.onSuccess(jsonObject);
            }

            @Override
            public void onFailure() {
                super.onFailure();
                baseCallBack.onFailure();
            }


            @Override
            public void onFailure(Throwable throwable) {
                super.onFailure(throwable);
                baseCallBack.onFailure(throwable);
            }
        });
    }

    /**
     * 城市行业占饼图
     *
     * @param topBrandCount
     * @param lastWeek
     * @param lastWeekCount
     * @param brand
     * @param bigRegion
     * @param officeName
     * @param cityName
     * @param baseCallBack
     */
    public void loadPiePicture(int topBrandCount, String lastWeek, int lastWeekCount, String brand, String bigRegion, String officeName, String cityName, final BaseCallBack baseCallBack) {
        JSONObject jsonObject = new JSONObject();
        try {
            JSONArray array = new JSONArray();
            array.put("热水器");
            array.put("燃气热水器");
            array.put("电储水热水器");
            array.put("净化器");
            array.put("净水器");
            jsonObject.put("categories", array);
            jsonObject.put("topBrandCount", topBrandCount);
            jsonObject.put("lastWeek", lastWeek);
            jsonObject.put("lastWeekCount", lastWeekCount);
            jsonObject.put("brand", brand);
            jsonObject.put("bigRegion", bigRegion);
            jsonObject.put("officeName", officeName);
            jsonObject.put("cityName", cityName);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        AvcHttpUtils.post(AvcConstants.URLHeaderCitys + "marketShare", jsonObject, true, new AvcJsonHttpResponseHandler(mContext) {

            @Override
            public void onSuccess(JSONObject jsonObject) {
                super.onSuccess(jsonObject);
                baseCallBack.onSuccess(jsonObject);
            }

            @Override
            public void onFailure() {
                super.onFailure();
                baseCallBack.onFailure();
            }

            @Override
            public void onFailure(Throwable throwable) {
                super.onFailure(throwable);
                baseCallBack.onFailure(throwable);
            }


        });
    }
}
